const unirest = require("unirest");
const config = require("../config");
const serverUrl = config.serverUrl;

const getStudioPageData = function (studioId) {
    return new Promise(function (resolve, reject) {
        let data = {
            "title": "工作室name",
            "studioBanner": "/img/studioBanner/01.jpg",
            "studioSliderPhotos": [
                {
                    "id": 1,
                    "url": "/img/studioSlider/01.jpg"
                },
                {
                    "id": 2,
                    "url": "/img/studioSlider/02.jpg"
                },
                {
                    "id": 3,
                    "url": "/img/studioSlider/03.jpg"
                }
            ],
            "studioContent": [
                {
                    "id": 1,
                    "url": "/img/studioContent/01.jpg"
                },
                {
                    "id": 2,
                    "url": "/img/studioContent/02.jpg"
                },
                {
                    "id": 3,
                    "url": "/img/studioContent/03.jpg"
                },
                {
                    "id": 4,
                    "url": "/img/studioContent/04.jpg"
                },
            ]
        }

        setTimeout(function () {
            resolve(data);
        }, 50);

        // let req = unirest("GET", serverUrl + "/api/studio/" + studioId + "/page");
        // req.end(function (res) {
        //     resolve(res.body);
        //     if (res.error) throw new Error(res.error);
        //     // 网络异常处理
        //     // 
        // });
    });
};

const getStudioData = function (studioId) {
    return new Promise(function (resolve, reject) {
        let data = {
            "serviceId": "23443511",
            "studioId": "123",
            "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写",
            "title2": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写",
            "price": "1000.00",
            "preview": "img/serviceLogo/08.webp",
        };
        setTimeout(function () {
            resolve(data);
        }, 50);
    });
};


// input studio id, return a service array
const getStudioService = function (serviceId) {

    return new Promise(function (resolve, reject) {
        let data = {           
            "services": [
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/08.webp",
                    "price": "￥100",
                    "serviceClass": "web",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },

                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/02.webp",
                    "price": "￥100",
                    "serviceClass": "text",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/07.webp",
                    "price": "￥100",
                    "serviceClass": "media",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/03.webp",
                    "price": "￥100",
                    "serviceClass": "web",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/04.webp",
                    "price": "￥100",
                    "serviceClass": "text",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/05.webp",
                    "price": "￥100",
                    "serviceClass": "web",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/06.webp",
                    "price": "￥100",
                    "serviceClass": "media",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
                {
                    "serviceId": "23443511",
                    "studioId": "123",
                    "preview": "/img/serviceLogo/01.webp",
                    "price": "￥100",
                    "serviceClass": "media",
                    "title": "网站建设 网站开发 H5网页编写 微信小程序 网站开发 H5网页编写"
                },
            ],
        }

        setTimeout(function () {
            data.services.forEach(element => {
                element.url = "/studio/" + element.studioId + "/service/" + element.serviceId
            });
            resolve(data);
        }, 50);
    });
};


const getHotStudio = function (studioId) {
    return new Promise(function (resolve, reject) {
        let data = {
            "hotStudios": [
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/01.webp"
                },

                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/02.webp"
                },
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/03.webp"
                },
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/04.webp"
                },
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/05.webp"
                },
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/04.webp"
                },
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/01.webp"
                },
                {
                    "studioId": "3253545",
                    "title": "studioName",
                    "preview": "img/studioLogo/02.webp"
                },
            ]
        }


        setTimeout(function () {
            data.hotStudios.forEach(element => {
                element.url = "/studio/" + element.studioId
            });
            resolve(data);
        }, 50);
    })
};


module.exports = {
    getStudioPageData,
    getStudioData,
    getStudioService,
    getHotStudio
}
